home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.misc
- subject: v11i025: dialout -- another kill getty and kermit prog
- From: nelson@uncecs.edu@uncw.uucp (Jim Nelson)
- Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
-
- Posting-number: Volume 11, Issue 25
- Submitted-by: nelson@uncecs.edu@uncw.uucp (Jim Nelson)
- Archive-name: dialout/part01
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of shell archive."
- # Contents: README dialout.1 Makefile dialout.c avatex.h courier.h
- # avatex.data courier.data
- # Wrapped by nelson@uncw on Sun Mar 11 15:58:35 1990
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'README' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'README'\"
- else
- echo shar: Extracting \"'README'\" \(841 characters\)
- sed "s/^X//" >'README' <<'END_OF_FILE'
- XA program to kill the [getty|uugetty] on a terminal line,
- Xand bring up a "kermit" on that line. If the kermit is
- Xshut down garacefully, the [getty|uugetty] is restarted.
- XAttempts to gracefully interface with uucp and kermit
- Xvia the "standard" lockfiles (your mileage in this regard
- Xmay vary). Works (has worked) with BSD 4.2 and SysVR3.
- XYour luck with having a uugetty behave rationally with
- Xkermit and/or uucp is problematical.
- XTo install: edit avatex.h and courier.h to reflect your
- X"tty" lines. Then edit Makefile to reflect your system.
- XThen "make". Then (you'll have to go root here) "make install".
- XYou must be root to install this program, and it must run
- Xsuid root (lockfile stuff, etc.). Examine the source carefully
- Xif you are wary of suid root programs.
- XPublic domain.
- X-- jim nelson, unc-wilmington, nelson@ecsvax.uncecs.edu
- END_OF_FILE
- if test 841 -ne `wc -c <'README'`; then
- echo shar: \"'README'\" unpacked with wrong size!
- fi
- # end of 'README'
- fi
- if test -f 'dialout.1' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'dialout.1'\"
- else
- echo shar: Extracting \"'dialout.1'\" \(400 characters\)
- sed "s/^X//" >'dialout.1' <<'END_OF_FILE'
- X.TH DIALOUT 1 Local
- X.UC 4
- X.SH NAME
- Xdialout \- kill getty and bring up kermit on modem
- X.SH SYNOPSIS
- X.B dialout
- X.SH DESCRIPTION
- XShuts down the getty and brings up Kermit on the 1200 baud
- Xcourier modem line (/dev/ttyd8).
- X.SH NOTES
- XThe user should be familiar with the AT command set for the
- Xparticular modem in use (Courier 1200, in this case).
- X.SH AUTHOR
- XJ. Nelson, UNCW, BSD 21 Apr 89, SysV 11 Mar 90
- END_OF_FILE
- if test 400 -ne `wc -c <'dialout.1'`; then
- echo shar: \"'dialout.1'\" unpacked with wrong size!
- fi
- # end of 'dialout.1'
- fi
- if test -f 'Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile'\"
- else
- echo shar: Extracting \"'Makefile'\" \(1230 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- XCFLAGS=
- XSYS=SYSV#BSD
- X
- X#/*where to install this thing*/
- XWHERE=/usr/local/bin
- X
- Xall: dirs dial2400 dialout
- X
- Xdialout: dialout.o
- X cp courier.h courier/dialout.h
- X cc -s -o dialout dialout.o
- X
- Xdial2400: dial2400.o
- X cp avatex.h avatex/dialout.h
- X cc -s -o dial2400 dial2400.o
- X
- Xdialout.o: dialout.c courier.h
- X cp courier.h courier/dialout.h
- X cc -D$(SYS) -c -Icourier dialout.c
- X
- Xdial2400.o: dialout.c avatex.h
- X rm -f dial2400.c
- X cp avatex.h avatex/dialout.h
- X ln dialout.c dial2400.c
- X cc -D$(SYS) -c -Iavatex dial2400.c
- X
- Xinstall: dialout dial2400
- X mv dialout $(WHERE)/dialout
- X chown root $(WHERE)/dialout
- X chmod u+s $(WHERE)/dialout
- X mv dial2400 $(WHERE)/dial2400
- X chown root $(WHERE)/dial2400
- X chmod u+s $(WHERE)/dial2400
- X cp avatex.data $(WHERE)/avatex.data
- X cp courier.data $(WHERE)/courier.data
- X
- Xclean:
- X rm -f dialout dial2400* *.i *.o
- X
- Xdirs: avatex courier avatex.h courier.h avatex.data courier.data
- X
- Xavatex:
- X sh -c "if test -d avatex; then : ;else mkdir avatex;fi"
- X
- Xcourier:
- X sh -c "if test -d courier; then : ;else mkdir courier;fi"
- X
- Xkit:
- X cp avatex/dialout.h ./avatex.h
- X cp $(WHERE)/avatex.data ./avatex.data
- X cp courier/dialout.h ./courier.h
- X cp $(WHERE)/courier.data ./courier.data
- X shar README *1 Makefile dialout.c *.h *.data>kit
- END_OF_FILE
- if test 1230 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- if test -f 'dialout.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'dialout.c'\"
- else
- echo shar: Extracting \"'dialout.c'\" \(4936 characters\)
- sed "s/^X//" >'dialout.c' <<'END_OF_FILE'
- X/* program to kill getty & bring up kermit on a tty line*/
- X/* probably dynix specific ... don't know, don't care */
- X/* j. nelson, (nelson@uncw.uucp) (nelson@ecsvax.uncecs.edu) */
- X/* latest revision
- XSat Mar 10 15:32:08 EST 1990
- X*/
- X#include <stdio.h>
- X#include <fcntl.h>
- X#include <pwd.h>
- X#include <sys/types.h>
- X#include <sys/stat.h>
- X
- X#include "dialout.h"
- X/* the dialout.h files should be in specific subdirectories, e.g.*/
- X/*avatex, courier, etc. */
- Xmain(argc,argv)char *argv[];
- X{
- X int i,fd;
- X unsigned long t;
- X FILE *fp;
- X char buf[120], name[12], *strncpy();
- X struct passwd *p, *getpwuid();
- X char *q, *getlogin();
- X
- X (void)argc;
- X (void)argv; /*strictly for lint*/
- X q=getlogin();
- X if(!authorized(q)){
- X fprintf(stderr,"%s not authorized to dialout\n",q);
- X exit(1);
- X }
- X {
- X fp=fopen("/tmp/dialoutlog","a");
- X if(!fp)exit(2);
- X t=time(0);
- X fprintf(fp," + %s %s",q,ctime(&t));
- X fclose(fp);
- X
- X }
- X if(geteuid()!=0){
- X fprintf(stderr,"oops, this prog should be setuid root\n");
- X error(1);
- X }
- X fiddle();
- X p = getpwuid(getuid());
- X (void)strncpy(name,p->pw_name,11);
- X for(i=0;i<12;i++)if(name[i]<' ' || name[i]>0176)name[i]=0;
- X fprintf(stderr,"%s\n",name);
- X if(stat(LCKFILE,(struct stat *)0)>=0)
- X {
- X fd=open(LCKFILE,0);
- X if(fd>=0){
- X fprintf(stderr,"oops\n");
- X fprintf(stderr,"%s busy\n",LCKFILE);
- X i=read(fd,buf,11);
- X if(i>0)fprintf(stderr,"by %s ... try later\n",buf);
- X error(2);
- X }
- X }
- X else {
- X fprintf(stderr,"ok no lock\n");
- X }
- X (void)system(SED1);
- X/* (void)system(" diff /etc/ttys /tmp/dialout.tmp");*/
- X (void)system(DIFF1);
- X/* (void)system(" cp /etc/ttys /etc/ttys.bak.tst");*/
- X (void)system(CP1);
- X/* (void)system(" cp /tmp/dialout.tmp /etc/ttys");*/
- X (void)system(CP2);
- X i=kill(1,1); /*kill(pid,signal)*/
- X if(i<0){
- X fprintf(stderr,"could not kill(1,1)\n");
- X error(3);
- X }
- X (void)system(" rm -f /tmp/dialout.tmp" );
- X fd=open(DEVICE,1);
- X if(fd<0){
- X error(4);
- X }
- X i=write(fd,S1,S1L);
- X if(i<0)error(5);
- X sleep(1);
- X (void)system(CAT);
- X
- X fiddle();
- X/* i=fchown(fd,getuid(),getgid());*/
- X/* apparently SysV does not have fchown() nor fchmod() :-( */
- X i=chown(DEVICE,getuid(),getgid());
- X if(i<0)error(6);
- X/* i=fchmod(fd,0666);*/
- X i=chmod(DEVICE,0666);
- X if(i<0)error(7);
- X i=close(fd);
- X if(i<0)error(8);
- X
- X if(fork()==0)
- X {
- X /*child*/
- X i=setuid(getuid());/*relinquish root privileges in child*/
- X if(i<0 || geteuid()==0)error(9);
- X fprintf(stderr,"PLEASE exit from kermit normally so that\n");
- X fprintf(stderr,"the modem line can be reset properly.\n");
- X fprintf(stderr,
- X "The proper way is ctrl-\\, then \"c\", then \"ex\"\n");
- X
- X (void)execl(KERMIT,"kermit","-l",DEVICE,
- X "-b",SPEED,(char *)NULL);
- X fprintf(stderr,"exec failed\n");/*should never happen*/
- X error(10);/*should never happen*/
- X }
- X else
- X {
- X /*parent*/
- X /* (parent is still root) */
- X (void)wait(0);
- X fd=open(DEVICE,1);
- X if(fd<0){
- X error(11);
- X }
- X i=write(fd,S2,S2L);
- X if(i<0)error(12);
- X fprintf(stderr,"wait...\n");
- X sleep(2);
- X/* i=fchown(fd,0,0);*/
- X i=chown(DEVICE,0,0);
- X if(i<0)error(6);
- X/* i=fchmod(fd,0666);*/
- X i=chmod(DEVICE,0666);
- X if(i<0)error(7);
- X i=close(fd);
- X if(i<0)error(13);
- X (void)unlink(LCKFILE); /*ignore error, because kermit didit*/
- X (void)system(SED2);
- X
- X/* (void)system(" diff /etc/ttys /tmp/dialout.tmp");*/
- X (void)system(DIFF2);
- X/* (void)system(" cp /tmp/dialout.tmp /etc/ttys");*/
- X (void)system(CP3);
- X i=kill(1,1); /*kill(pid,signal)*/
- X if(i== -1){
- X fprintf(stderr,"could not kill(1,1)\n");
- X if(getuid()!=0 && getuid()!=100)error(14);
- X }
- X (void)system(" rm -f /tmp/dialout.tmp" );
- X
- X
- X fp=fopen("/tmp/dialoutlog","a");
- X if(!fp)exit(2);
- X t=time(0);
- X fprintf(fp," - %s %s",q,ctime(&t));
- X fclose(fp);
- X
- X
- X }
- X}
- Xfiddle()
- X{
- X struct passwd *p;
- X struct stat zork;
- X int i,c;
- X i=stat(DEVICE,&zork);
- X if(i<0)error(15);
- X if(zork.st_uid != 0){
- X p=getpwuid(zork.st_uid);
- X fprintf(stderr,
- X "the modem seems to be owned by %s\n",/*zork.st_uid*/p->pw_name);
- X fprintf(stderr,"do you wish to barge right on through?");
- X c=getchar(); while(getchar()!='\n');
- X if(c!='y')error(16);
- X }
- X if((zork.st_mode & 0777) != 0622){
- X fprintf(stderr,"%s has wrong mode\n",DEVICE);
- X fprintf(stderr,"do you wish to barge right on through?");
- X c=getchar(); while(getchar()!='\n');
- X if(c!='y')error(17);
- X }
- X}
- Xerror(i)
- X{
- X FILE *fp;
- X char *q;
- X unsigned long t;
- X fprintf(stderr,"error %d\n",i);
- X (void)fflush(stderr);
- X fp=fopen("/tmp/dialoutlog","a");
- X if(!fp)exit(2);
- X t=time(0);
- X q=getlogin();
- X fprintf(fp," - error %d %s %s",i,q,ctime(&t));
- X fclose(fp);
- X exit(i);
- X}
- Xkindex(s,t)
- Xchar s[],t[];
- X{
- X int c,i,j,k;
- X c=s[0];
- X if(c==0){return -1;
- X }
- X c=t[0];
- X if(c==0){return -1;
- X }
- X for(i=0;s[i] !='\0'; i++){
- X for(j=i,k=0;t[k] !='\0' && s[j]==t[k];j++,k++)
- X ;
- X if(t[k]=='\0')return (i);
- X }
- X return(-1);
- X}
- Xauthorized(name)
- Xchar *name;
- X{
- X FILE *fp;
- X int k;
- X char buf[99];
- X fp=fopen(AUTHFILE,"r");
- X if(!fp)return 0;
- X while( fgets(buf,98,fp)==buf){
- X if(kindex(buf,name)==0){
- X fclose(fp);
- X return 1;
- X }
- X }
- X fclose(fp);
- X return 0;
- X
- X}
- END_OF_FILE
- if test 4936 -ne `wc -c <'dialout.c'`; then
- echo shar: \"'dialout.c'\" unpacked with wrong size!
- fi
- # end of 'dialout.c'
- fi
- if test -f 'avatex.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'avatex.h'\"
- else
- echo shar: Extracting \"'avatex.h'\" \(1200 characters\)
- sed "s/^X//" >'avatex.h' <<'END_OF_FILE'
- X#define LCKFILE "/usr/spool/uucp/LCK/LCK..ttyh0"
- X#define KERMIT "/usr/uncw/kermit" /*where you keep your kermit*/
- X#ifdef BSD
- X#define DEVICE "/dev/ttyh0"
- X#else
- X#define DEVICE "/dev/contty"
- X#endif
- X#define SPEED "2400"
- X#define S1 "ate1q0x4v1\015"
- X#define S2 "atz\015"
- X#define S1L strlen(S1)
- X#define S2L strlen(S2)
- X#ifdef BSD
- X#define SED1 "sed '/ttyh0/s/^1/0/' /etc/ttys >/tmp/dialout.tmp"
- X#define SED2 "sed '/ttyh0/s/^0/1/' /etc/ttys >/tmp/dialout.tmp"
- X#else
- X/*SysV*/
- X#define SED1 "sed '/^ct:/s/respawn/off/' /etc/inittab>/tmp/dialout.tmp"
- X#define SED2 "sed '/^ct:/s/off/respawn/' /etc/inittab>/tmp/dialout.tmp"
- X#endif
- X#define CAT "cat /usr/lib/uucp/avatex.data"
- X#define AUTHFILE "/etc/dialout.auth"
- X#ifdef BSD
- X#define DIFF1 "diff /etc/ttys /tmp/dialout.tmp"
- X#define CP1 "cp /etc/ttys /etc/ttys.bak.tst"
- X#define CP2 "cp /tmp/dialout.tmp /etc/ttys"
- X#define DIFF2 "diff /etc/ttys /tmp/dialout.tmp"
- X#define CP3 "cp /tmp/dialout.tmp /etc/ttys"
- X#else
- X#define DIFF1 "diff /etc/inittab /tmp/dialout.tmp"
- X#define CP1 "cp /etc/inittab /etc/ttys.bak.tst"
- X#define CP2 "cp /tmp/dialout.tmp /etc/inittab"
- X#define DIFF2 "diff /etc/inittab /tmp/dialout.tmp"
- X#define CP3 "cp /tmp/dialout.tmp /etc/inittab"
- X#endif
- END_OF_FILE
- if test 1200 -ne `wc -c <'avatex.h'`; then
- echo shar: \"'avatex.h'\" unpacked with wrong size!
- fi
- # end of 'avatex.h'
- fi
- if test -f 'courier.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'courier.h'\"
- else
- echo shar: Extracting \"'courier.h'\" \(1200 characters\)
- sed "s/^X//" >'courier.h' <<'END_OF_FILE'
- X#define LCKFILE "/usr/spool/uucp/LCK/LCK..ttyh0"
- X#define KERMIT "/usr/uncw/kermit" /*where you keep your kermit*/
- X#ifdef BSD
- X#define DEVICE "/dev/ttyh8"
- X#else
- X#define DEVICE "/dev/contty"
- X#endif
- X#define SPEED "1200"
- X#define S1 "ate1q0x4v1\015"
- X#define S2 "atz\015"
- X#define S1L strlen(S1)
- X#define S2L strlen(S2)
- X#ifdef BSD
- X#define SED1 "sed '/ttyh0/s/^1/0/' /etc/ttys >/tmp/dialout.tmp"
- X#define SED2 "sed '/ttyh0/s/^0/1/' /etc/ttys >/tmp/dialout.tmp"
- X#else
- X/*SysV*/
- X#define SED1 "sed '/^ct:/s/respawn/off/' /etc/inittab>/tmp/dialout.tmp"
- X#define SED2 "sed '/^ct:/s/off/respawn/' /etc/inittab>/tmp/dialout.tmp"
- X#endif
- X#define CAT "cat /usr/lib/uucp/avatex.data"
- X#define AUTHFILE "/etc/dialout.auth"
- X#ifdef BSD
- X#define DIFF1 "diff /etc/ttys /tmp/dialout.tmp"
- X#define CP1 "cp /etc/ttys /etc/ttys.bak.tst"
- X#define CP2 "cp /tmp/dialout.tmp /etc/ttys"
- X#define DIFF2 "diff /etc/ttys /tmp/dialout.tmp"
- X#define CP3 "cp /tmp/dialout.tmp /etc/ttys"
- X#else
- X#define DIFF1 "diff /etc/inittab /tmp/dialout.tmp"
- X#define CP1 "cp /etc/inittab /etc/ttys.bak.tst"
- X#define CP2 "cp /tmp/dialout.tmp /etc/inittab"
- X#define DIFF2 "diff /etc/inittab /tmp/dialout.tmp"
- X#define CP3 "cp /tmp/dialout.tmp /etc/inittab"
- X#endif
- END_OF_FILE
- if test 1200 -ne `wc -c <'courier.h'`; then
- echo shar: \"'courier.h'\" unpacked with wrong size!
- fi
- # end of 'courier.h'
- fi
- if test -f 'avatex.data' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'avatex.data'\"
- else
- echo shar: Extracting \"'avatex.data'\" \(7 characters\)
- sed "s/^X//" >'avatex.data' <<'END_OF_FILE'
- XHayes?
- END_OF_FILE
- if test 7 -ne `wc -c <'avatex.data'`; then
- echo shar: \"'avatex.data'\" unpacked with wrong size!
- fi
- # end of 'avatex.data'
- fi
- if test -f 'courier.data' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'courier.data'\"
- else
- echo shar: Extracting \"'courier.data'\" \(777 characters\)
- sed "s/^X//" >'courier.data' <<'END_OF_FILE'
- Xc0=transmitter disabled, c1=transmitter enabled
- Xd p=pulse, t=tone, ','=pause 2 sec, ';'=return to command state
- X !=flash hook, w=wait for 2nd dialtone (x3 or higher)
- X @=wait for answer (x3 or higher), r=reverse roles
- Xe0=echo off, e1=echo on
- Xf0=half duples, f1=full duples
- Xh0=hang up, h1=go off hook
- Xi0=product code, i1=rom cksum, i2=ram test, i3=return call duration/
- X real time, i4=display current settings
- Xk0=at ati3 display call duration, k1=real time
- Xm0=speaker off, m1=speaker on until connect, m2=always on
- Xo=return online
- Xp=pulse dial
- Xq0=result codes displayed, q1=quiet mode
- Xv0=numeric mode, v1=verbal mode
- Xx0-6=verbosity level(6 is most verbose)
- Xz=reset to default
- X>=repeat command continuously
- X$=help command summary
- XD$=dial help commands
- Xs$=s-reg help commands
- X
- END_OF_FILE
- if test 777 -ne `wc -c <'courier.data'`; then
- echo shar: \"'courier.data'\" unpacked with wrong size!
- fi
- # end of 'courier.data'
- fi
- echo shar: End of shell archive.
- exit 0
-
-